ServerOptions: different input & output device names only works on osx
[supercollider.git] / examples / GUI examples / strike.scd
blob3780fd9d7aee95c9751eaafdc1098fbc747bec35
1 // strike
2 // Julian Rohrhuber, 2006
4 GUI.cocoa;      // use Mac OS X native GUI
5 GUI.swing;      // use Java GUI
7 // neon
9         var xx, yy, x, y, c, width, z=1, pp, zz=0, mm=10, alph=1.0, pen;
10         width = 1;
11         w = Window(Char.bullet, Rect(100, 100, 600, 600)).front;
12         w.view.background_(Color.gray(0.6));
14         v = UserView(w, w.view.bounds).mouseMoveAction_({|v,ax,ay| 
15                 x = ax; y = ay;
16                 
17                 4.do {
18                                 [xx, yy].choose.value([5, -5, 2, -2, 8, -8].choose * 2);
19                                 
20                 };
21                 
22          });
23         
24         x = 200; y = 100;
25         xx = { |d=1| c = c.add((x = x + d) @ y ).keep(-150) };
26         yy = { |d=1| c = c.add(x @ (y = y + d)).keep(-150) };
27         c = [];
28         20.do {
29                         [xx, yy].choose.value([10, -10, 5, -5, 2, -2].choose * 2);
30                         
31         };
32         pen = Pen;
33         w.drawHook = {
34                 // set the Color
35                 try { pen.smoothing_(false) };
36                 pen.width = width;
37                 z.do { |i|
38                         pen.strokeColor = Color.rand.alpha_(i.linexp(0, z-1, 1.0, alph));
39                         pen.moveTo(c[0]);
40                         c.size.do { |i| Pen.lineTo(c.wrapAt(i)) };
41                         pen.stroke;
42                         pen.translate([-2, -2, 2, 2] @@ zz, [-2, 2, -2, 2]*2 @@ zz);
43                         
44                 };
45                 z = z + 1 % mm;
46                 if(z % mm == 0) { zz = zz + 1; mm = rrand(5, 20); alph = #[0.1, 1.0].choose };
47         };
48         w.refresh;
49         fork {Êloop {Ê0.1.wait; defer {Êw.refresh; } } };
51                 
52                 
53                 
54                 
55         
56         
57 // tetris
59                 var xx, yy, x, y, c, d, width, viewheight;
60                 var phunz, steps, nKeep, pen;
61                 
62                 q = q ?? ();
63                 
64                 width = 1;
65                 w = Window(Char.bullet, Rect(100, 100, 400, 400)).front;
66                 w.view.background_(Color.black);
67         
68                 viewheight = w.bounds.height;
69                 nKeep = 20;
70                 x = 200; 
71                 y = 100;
72                 steps = #[1, 1, 2, 2, 2, 2, 4];
73                 
74                 v = UserView(w, w.view.bounds);
75                 v.mouseMoveAction_({|v,ax,ay| 
76                         x = ax; y = ay;
77                         phunz.(8);
78                         q.updateData(d);
79                  });
80                  v.mouseUpAction_({|v,ax,ay| 
81                         q.sendData(d);
82                  });
83                 
84                 phunz = { arg n=1;
85                         var scale = y.linexp(0, viewheight, 1, 40);
86                         c = [];
87                         n.do {
88                                 [xx, yy].choose.value(steps.choose * #[1, -1].choose * scale);
89                                         
90                         };
91                         d = d.add(c).keep(nKeep.neg);
92                 };
93                 
94                 xx = { |d=1| c = c.add((x = x + d) @ y ) };
95                 yy = { |d=1| c = c.add(x @ (y = y + d)) };
96                 
97                 phunz.(20);
98                 pen = Pen;
99                 w.drawHook = {
100                         
101                         try { pen.smoothing_(false) };
102                         
103                         pen.width = width; 
104                         
105                         d.do { |x, i| 
106                                 pen.moveTo(x[0]);
107                                 x.do { |point|
108                                         pen.strokeColor = blend(
109                                                 Color.green, 
110                                                 Color.yellow, 
111                                                 point.y.linlin(0, viewheight, 1, -1)
112                                         ).alpha_(point.y.linexp(0, viewheight, 0.5, 0.1));
113                                         pen.lineTo(point);
114                                 };
115                                 pen.stroke;
116                         };
117                         d = d.deepCollect(2, { |x| x.y = x.y + 0.5 % viewheight });
118         
119                 };
120                 w.refresh;
121                 {Êloop {Ê0.015.wait; w.refresh }}.fork( AppClock );
126 // sound for tetris
128 p = ProxySpace(s.boot);
129 p.play(\out);
130 p.clock = TempoClock.default;
131 p.fadeTime = 3;
133 q.sendData = {|q, data|
134         
135         var ugens;
136         p[\out] = {
137                 data.do { |array|
138                         var xdata, ydata, xmul, ymul;
139                         array.do {Ê|point|
140                                 xdata = xdata.add(point.x);
141                                 ydata = ydata.add(point.y);
142                         };
143                         xmul = 11;
144                         ymul = 1;
145                         ugens = ugens.addAll([
146                                 LFPulse.ar(Duty.ar(0.4, 0, Dseq(xdata, inf) * xmul), 0, 0.5)
147                                 ,
148                                 Formant.ar(Duty.ar(0.5 * ymul, 0, Dseq(ydata, inf) * ymul), 500, Duty.ar(0.02 * xmul, 0, Dseq(xdata, inf) * xmul))
149                         ]);
150                 };
151                 
152                 LPF.ar(ugens.mean, 3000) * 0.2 ! 2
153         }
155 };      
156 );